package com.ithema.manger.service;

import com.ithema.manger.dao.StudentDao;
import com.ithema.manger.domain.Student;

public class StudentService {
    //创建StudentDao的对象
    StudentDao studentDao=new StudentDao();

//添加学生判断
    public boolean addStudent(Student stu) {
        //调用StudentDao的addStudent方法,并返回是否添加成功
        //StudentDao studentDao=new StudentDao();
        return studentDao.addStudent(stu);
    }
//查看学生信息
    public Student[] findAllStudent() {
       //调用StudentDao的方法 findAllStudent
        //StudentDao studentDao=new StudentDao();
        Student[] stu=studentDao.findAllStudent();
        //遍历数组判断是否有信息
        for (int i = 0; i < stu.length; i++) {
            if(stu[i]!=null){
                return stu;
            }
        }return null;
    }
//判断学号是否存在
    public boolean isExists(String sid) {
        //调用StudentDao的findAllStudent方法
        Student[] student=studentDao.findAllStudent();
        //初定义
        boolean flag=false;
        //遍历数组
        for (int i = 0; i < student.length; i++) {
            Student stu=student[i];
            if(stu!=null&&sid.equals(stu.getSid())){
                flag=true;
            }
        }return flag;
    }
//删除学生
    public void delectStudent(String sid) {
        //调用StudentDao的方法 delectStudent
        studentDao.delectStudent(sid);
    }
//修改学生
    public void updateStudent(String updateSid, Student updateStu) {
       //调用StudentDao的方法updateStudent
       studentDao.updateStudent(updateSid,updateStu);
    }
}
